package com.it.dao;

import com.it.domain.Goods;
import com.it.domain.Goods_Details;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository
public interface GoodsDao {
    /**
     * 新建货物
     * @param goods
     */
    @Insert("INSERT INTO Goods (NAME,Product_Types,Supplier,Supplier_Contact)\n" +
            "\tVALUES(#{name},#{Product_Types},#{Supplier},#{Supplier_Contact})")
    void saveGoods(Goods goods);

    /**
     * 插入货物内容
     * @param goods_details
     */
    @Insert("INSERT INTO Goods_Details (id_d,NAME,details,Quantity,Production_Date,Shelf_life,Purchase_price,Shipping_price)\n" +
            "\tVALUES(#{id_d},#{name},#{details},#{Quantity},#{Production_Date},#{Shelf_life},#{Purchase_price},#{Shipping_price})")
    void saveGoods_Details(Goods_Details goods_details);

    /**
     * 查询所有货物
     * @return
     */
    @Select("SELECT * FROM Goods")
    List<Goods> findAllGoods();

    /**
     * 根据名称模糊查询货物
     * @param name
     * @return
     */
    @Select("SELECT * FROM Goods WHERE NAME LIKE concat('%',#{name},'%')")
    List<Goods> FindByName(String name);



    /**
     * 根据id修改信息
     * @param goods
     * @param
     */
    @Update("UPDATE Goods SET NAME = #{name},Product_Types=#{Product_Types},Supplier=#{Supplier},Supplier_Contact=#{Supplier_Contact} WHERE id = #{id}")
    void changeGoods(Goods goods);

    /**
     * 根据id查询goods表
     * @param id
     * @return
     */
    @Select("select * from Goods where id = #{id}")
    List<Goods> FindById(int id);

    /**
     * 根据名称查询goodsdetails表
     * @param name
     * @return
     */
    @Select("select * from Goods_Details where name = #{name}")
    List<Goods_Details> FindByNameGD(String name);

    /**
     * 根据名称修改goodsdetails表
     * @param
     * @param
     */
    @Update("UPDATE Goods_Details SET NAME = #{name} WHERE id_d = #{id_d}")
    void ChangeGDName(Goods_Details goods_details/*,int id_d*/);

    /**
     * 根据id删除goods
     * @param id
     */
    @Delete("delete from Goods where id = #{id}")
    void delGoods(int id);

    /**
     * 根据id删除goodsdetails所有相关信息
     * @param id_d
     */
    @Delete("delete from Goods_Details where id_d = #{id_d}")
    void delGoodsDetails(int id_d);

    /**
     * 删除货物详情一项根据
     * @param details
     */
    @Delete("delete from Goods_Details where details = #{details}")
    void delGoodsDetailsBydetails(String details);
    /**
     * 根据名称查询所有details
     * @return
     */
    @Select("SELECT * from Goods_Details where name = #{name}")
    List<Goods_Details> SelectGoodsDetails(String name);

    /**
     * 根据details修改goods details信息
     * @param goods_details
     */
    @Update("UPDATE Goods_Details SET Quantity=#{Quantity},Production_Date=#{Production_Date},Shelf_life=#{Shelf_life},Purchase_price=#{Purchase_price},Shipping_price=#{Shipping_price} WHERE details = #{details}")
    void ChangeDetails(Goods_Details goods_details);

    /**
     * 根据details 改变数量
     * @param goods_details
     * @param
     */
    @Update("UPDATE Goods_Details set Quantity = #{Quantity} WHERE details = #{details} ")
    void IoDGoodsDetails (Goods_Details goods_details);

    /**
     * 根据details查询相应数量
     * @param details
     * @return
     */
    @Select("SELECT Quantity FROM Goods_Details WHERE details=#{details}")
    int selectQuantity(String details);

    /**
     * 根据名称模糊查询货物
     * @param details
     * @return
     */
    @Select("SELECT * FROM Goods_Details WHERE details LIKE concat('%',#{details},'%')")
    List<Goods_Details> FindBydetails(String details);

    /**
     * 查询所有货物详情
     * @return
     */
    @Select("select * from Goods_Details")
    List<Goods_Details> FindAlldetails();

    /**
     *类型查询
     * @return
     */
    @Select("select * from Goods where Product_Types=#{Product_Types}")
    List<Goods> FindSomeGoods(String Product_Types);

    /**
     * 根据details查询goods——details货物
     * @param details
     * @return
     */
    @Select("SELECT * FROM Goods_Details WHERE details = #{details}")
    List<Goods_Details> FindGoodsByDetails(String details);
}
